<template>
    <view class="menu-grid bg-fff">
        <view class="menu-item font12" v-for="(item, index) in menuItems" :key="index" @click="clickMenu(item)">
            <image class="menuImg" :src="item.icon" mode="aspectFit"></image>
            <text>{{item.name}}</text>
        </view>
    </view>
</template>

<script setup>
    import { ref } from "vue";

    //menus
    let menuItems = ref([
        { 
            name: '房源货架',
            type: 'fangYuan',
            path: '/pages/products/find/index',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-hot.png' 
        },
        { 
            name: '库存汇总', 
            type: 'kuCun',
            path: '/pages/products/ku-cun/index',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-kucun.png' 
        },
		{ 
            name: '上市预告', 
            type: 'yuGao',
            path: '/pages/products/shangshi-yugao/index',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-shangshi-yugao.png' 
        },
		{ 
            name: '开盘日历', 
            type: 'riLi',
            path: '/pages/tools/calendar/index',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-kaipan-rili.png' 
        },
		{ 
            name: '一键查询', 
            type: 'chaXun',
            path: '/pages/tools/query-collect/index',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-chaxun.png' 
        },
		{ 
            name: '资格查询', 
            type: 'zhengce',
            path: '',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-zhengce.png' 
        },
		{ 
            name: '贷款咨询',
            type: 'daiKuan',
            path: '/pages/tools/dai-kuan/index',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-daikuan.png' 
        },
		{ 
            name: '以旧换新', 
            type: 'huanXin',
            path: '',
            icon: 'https://image.srea.org.cn/xcx/icon/icon-home-menu-yijiu-huanxin.png' 
        }
	])

    const props = defineProps({
        // 以旧换新
        huanXinData: {
            type: Array,
            default: []
        },
        // 资格查询
        policyData: {
            type: Array,
            default: []
        }
    })

    //点击menu
	function clickMenu(info) {
        switch(info.type) {
            case 'zhengce':
                if(props.policyData.length === 1) {
                    uni.navigateTo({
                        url: `/pages/tools/policy-news/detail/index?detailId=${props.policyData[0].id}`
                    })
                }else {
                    uni.navigateTo({
                        url: `/pages/tools/policy-news/list/index`
                    })
                }
                break;
            case 'huanXin':
                if(props.huanXinData.length === 1) {
                    uni.navigateTo({
                        url: `/pages/tools/huan-xin/detail/index?detailId=${props.huanXinData[0].id}`
                    })
                }else {
                    uni.navigateTo({
                        url: `/pages/tools/huan-xin/list/index`
                    })
                }
                break;
            default:
                uni.navigateTo({
                    url: info.path
                })
                break;
        }
    }
</script>

<style lang="scss" scoped>
	.menu-grid {
		display: grid;
		grid-template-columns: repeat(4, 1fr);
		gap: 30rpx;
		padding: 30rpx 0;
        .menu-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            .menuImg {
                width: 60rpx;
                height: 60rpx;
                margin-bottom: 10rpx;
            }
        }
	}
</style>